package DBLayer;
import java.sql.*;

/**
 * GetMax.java
 * @version 12/22/2011
 * @author Gruppe 4
 */

public class GetMax 
{
    /**
     * Creates a new instance of GetMax
     */
    public GetMax() 
    {
        
    }
    
    /**
     * getMax is for the primary key in the table
     * @param query
     * @return returns the highest id of a given table in the database
     */			
    public static int getMaxId(String query)
    {
       	ResultSet results;
	int id = -1;
	try
        { 
	   Statement stmt = DBConnection.getInstance().getDBcon().createStatement();
	   results = stmt.executeQuery(query);
	   if(results.next())
           {
               id = results.getInt(1);
           }
        }//end try
        
	catch(Exception e)
        {
	    System.out.println("Query exception: Error in reading maxid" + e);
	}
        
	return id;
    }
}